home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / blanker / source / blankers / text / prefs.c < prev    next >
C/C++ Source or Header  |  1993-08-01  |  4KB  |  157 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3.  
  4. #include <dos/dos.h>
  5.  
  6. #include <intuition/intuition.h>
  7. #include <intuition/gadgetclass.h>
  8. #include <intuition/screens.h>
  9. #include <libraries/gadtools.h>
  10. #include <libraries/asl.h>
  11.  
  12. #include <clib/exec_protos.h>
  13. #include <clib/intuition_protos.h>
  14. #include <clib/gadtools_protos.h>
  15. #include <clib/asl_protos.h>
  16. #include <clib/alib_protos.h>
  17.  
  18. #include "Text.h"
  19. #include "Text_rev.h"
  20. #include "/defs.h"
  21. #include "/utility.h"
  22.  
  23. struct tPrefObject {
  24.     UBYTE text[128];
  25.     UBYTE fName[64];
  26.     UBYTE Speed;
  27.     UBYTE State;
  28.     UBYTE Cycle;
  29.     struct TextAttr Font;
  30. };
  31.  
  32. VOID blank( VOID );
  33.  
  34.     struct    tPrefObject    nP;
  35. STATIC    const    UBYTE    VersTag[] = VERSTAG;
  36. extern    struct    Task    **Task;
  37. extern        UBYTE   *prefData;
  38.  
  39. VOID setTextPrefs( VOID )
  40. {
  41.         GT_SetGadgetAttrs( TextGadgets[GD_SPEED], TextWnd, 0L, GTSL_Level, nP.Speed, 0L );
  42.     GT_SetGadgetAttrs( TextGadgets[GD_FTXT], TextWnd, 0L, GTTX_Text, nP.fName, 0L );
  43.     if( nP.State ) GT_SetGadgetAttrs( TextGadgets[GD_FONT], TextWnd, 0L, GA_Disabled, TRUE, 0L );
  44.     else GT_SetGadgetAttrs( TextGadgets[GD_FONT], TextWnd, 0L, GA_Disabled, FALSE, 0L );
  45.     GT_SetGadgetAttrs( TextGadgets[GD_FSIZE], TextWnd, 0L, GTNM_Number, nP.Font.ta_YSize, 0L );
  46.     GT_SetGadgetAttrs( TextGadgets[GD_TXT], TextWnd, 0L, GTST_String, nP.text, 0L );
  47.     GT_SetGadgetAttrs( TextGadgets[GD_SWITCH], TextWnd, 0L, GTCY_Active, nP.State, 0L );
  48.     GT_SetGadgetAttrs( TextGadgets[GD_CYCLE], TextWnd, 0L, GTCY_Active, nP.Cycle, 0L );
  49. }
  50.  
  51. int OKClicked( VOID )
  52. {
  53.     CopyMem( &nP, prefData, sizeof( struct tPrefObject ));
  54.     return( QUIT );
  55. }
  56.  
  57. int TESTClicked( VOID )
  58. {
  59.     *Task = FindTask( 0L );
  60.     blank();
  61.     return( CONTINUE );
  62. }
  63.  
  64. int CANCELClicked( VOID )
  65. {
  66.     return( QUIT );
  67. }
  68.  
  69. int SPEEDClicked( VOID )
  70. {
  71.     nP.Speed = TextMsg.Code;
  72.     return( CONTINUE );
  73. }
  74.  
  75. int SWITCHClicked( VOID )
  76. {
  77.     nP.State = TextMsg.Code;
  78.     setTextPrefs();
  79.     return( CONTINUE );
  80. }
  81.  
  82. int CYCLEClicked( VOID )
  83. {
  84.     nP.Cycle = TextMsg.Code;
  85.     return( CONTINUE );
  86. }
  87.  
  88. int FONTClicked( VOID )
  89. {
  90.     struct FontRequester *fReq;
  91.  
  92.     if( fReq = ( struct FontRequester * )AllocAslRequestTags( ASL_FontRequest, ASL_FontName, (ULONG)nP.fName,
  93.         ASL_FontHeight, nP.Font.ta_YSize, ASL_MaxHeight, 100, TAG_DONE )) {
  94.         if( AslRequestTags( fReq, ASLFO_Window, TextWnd, ASLFO_SleepWindow, TRUE, ASLFO_TitleText,
  95.             (ULONG)"Please choose a font...", 0L )) {
  96.             CopyMem( fReq->fo_Attr.ta_Name, nP.fName, 31 );
  97.             nP.Font.ta_YSize = fReq->fo_Attr.ta_YSize;
  98.         }
  99.         FreeAslRequest( fReq );
  100.     }
  101.     setTextPrefs();
  102.     return( CONTINUE );
  103. }
  104.  
  105. int TXTClicked( VOID )
  106. {
  107.     CopyMem( (( struct StringInfo * )( TextGadgets[GD_TXT] )->SpecialInfo )->Buffer, nP.text, 128 );
  108.     return( CONTINUE );
  109. }
  110.  
  111. int TextVanillaKey( VOID )
  112. {
  113.     switch( TextMsg.Code ) {
  114.     case 'o':
  115.         return( OKClicked() );
  116.     case 't':
  117.         return( TESTClicked() );
  118.     case 'c':
  119.         return( CANCELClicked() );
  120.     case 'f':
  121.         return( FONTClicked());
  122.     case 's':
  123.         GT_SetGadgetAttrs( TextGadgets[GD_SPEED], TextWnd, 0L, GTSL_Level, ++(nP.Speed) > 50 ?
  124.             nP.Speed = 50 : nP.Speed, 0L );
  125.         return( CONTINUE );
  126.     case 'S':
  127.         GT_SetGadgetAttrs( TextGadgets[GD_SPEED], TextWnd, 0L, GTSL_Level, --(nP.Speed) < 1 ?
  128.             nP.Speed = 1 : nP.Speed, 0L );
  129.         return( CONTINUE );
  130.     default:
  131.         return( CONTINUE );
  132.     }
  133. }
  134.  
  135. VOID prefs( LONG command )
  136. {
  137.     switch( command ) {
  138.     case STARTUP:
  139.         CopyMem( prefData, &nP, sizeof( struct tPrefObject ));
  140.         nP.Font.ta_Name = nP.fName;
  141.         if( !SetupScreen() ) {
  142.             if( !OpenTextWindow()) setTextPrefs();
  143.             CloseDownScreen();
  144.         }
  145.         break;
  146.     case IDCMP:
  147.         if( HandleTextIDCMP() != QUIT ) break;
  148.     case KILL:
  149.         CloseTextWindow();
  150.     }
  151. }
  152.  
  153. LONG winSig( VOID )
  154. {
  155.     return( TextWnd ? ( 1L << TextWnd->UserPort->mp_SigBit ) : 0L );
  156. }
  157.